package com.ruoyi.operation.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.operation.domain.*;
import com.ruoyi.operation.service.TradeingActivityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@Controller
@CrossOrigin
@RequestMapping("/payInfo/logic")
public class TradeingAcitvityController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(TradeingAcitvityController.class);

    @Autowired
    TradeingActivityService tradeingActivityService;

    @PostMapping("/getTradingActivityInfoByHour")
    @ResponseBody
    public TableDataInfo getTradingActivityInfoByHourList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<TradingActivity> list = tradeingActivityService.getTradeingActivityType("HOUR", requestBO);
        return getDataTable(list);
    }


    @PostMapping("/getTradingActivityInfoByMonth")
    @ResponseBody
    public TableDataInfo getTradingActivityInfoByMonthList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<TradingActivity> list = tradeingActivityService.getTradeingActivityType("MONTH", requestBO);
        return getDataTable(list);
    }


    @PostMapping("/getPayWayNum")
    @ResponseBody
    public TableDataInfo getPayWayNumList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<PayWayWIthNum> list = tradeingActivityService.getPayWayNum(requestBO);
        return getDataTable(list);
    }

    @PostMapping("/getMonthConsumer")
    @ResponseBody
    public TableDataInfo getMonthConsumerList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<MonthPrice> list = tradeingActivityService.getMonthPrice("CONSUMER", requestBO);
        return getDataTable(list);
    }

    @PostMapping("/getRepayment")
    @ResponseBody
    public TableDataInfo getRepaymentList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<MonthPrice> list = tradeingActivityService.getMonthPrice("REPAYMENT", requestBO);
        return getDataTable(list);
    }


    @PostMapping("/mechanismUseNum")
    @ResponseBody
    public TableDataInfo mechanismUseNumList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<MechanismUseNum> list = tradeingActivityService.getMechanismUseNumList(requestBO);
        return getDataTable(list);
    }

    @PostMapping("/getPlatformStatusList")
    @ResponseBody
    public TableDataInfo getPlatformStatusList(@RequestBody RequestBO requestBO) {
        startPage();
        List<PlatformStatus> list = tradeingActivityService.getPlatformStatusList(requestBO);
        return getDataTable(list);
    }

    @PostMapping("/getMonthApplyList")
    @ResponseBody
    public TableDataInfo getMonthApplyList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<MonthApply> list = tradeingActivityService.getMonthApplyList(requestBO);
        return getDataTable(list);
    }

    @PostMapping("/getMonthRefuseList")
    @ResponseBody
    public TableDataInfo getMonthRefuseList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<MonthApply> list = tradeingActivityService.getMonthRefuseList(requestBO);
        return getDataTable(list);
    }


    @PostMapping("/getPlatformSumCountList")
    @ResponseBody
    public TableDataInfo getPlatformSumCountList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<PlatformSumCount> list = tradeingActivityService.getPlatformSumCountList(requestBO);
        return getDataTable(list);
    }


    @PostMapping("/getLoanStautsList")
    @ResponseBody
    public TableDataInfo getLoanStautsList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<PlatformStatus> list = tradeingActivityService.getLoanStautsList(requestBO);
        return getDataTable(list);
    }


    @PostMapping("/getRepayStautsList")
    @ResponseBody
    public TableDataInfo getRepayStautsList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<PlatformStatus> list = tradeingActivityService.getRepayStautsList(requestBO);
        return getDataTable(list);
    }


    @PostMapping("/getRepayPlatformSumList")
    @ResponseBody
    public TableDataInfo getRepayPlatformSumList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<PlatformSumCount> list = tradeingActivityService.getRepayPlatformSumList(requestBO);
        return getDataTable(list);
    }


    @PostMapping("/getRepayPlatformMonthNumSumList")
    @ResponseBody
    public TableDataInfo getRepayPlatformMonthSumList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<MonthNumApply> list = tradeingActivityService.getRepayPlatformMonthNumSumList(requestBO);
        return getDataTable(list);
    }


    @PostMapping("/getUserInfoList")
    @ResponseBody
    public TableDataInfo getUserInfoList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<UserInfo> list = tradeingActivityService.getUserInfoList(requestBO);
        return getDataTable(list);
    }


    @PostMapping("/getTotalOutputList")
    @ResponseBody
    public TableDataInfo getTotalOutputList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<TotalOutPut> list = tradeingActivityService.getTotalOutputList(requestBO);
        return getDataTable(list);
    }

    //12个月的收入支出趋势
    @PostMapping("/getMonthInOutList")
    @ResponseBody
    public TableDataInfo getMonthInOutList(@RequestBody RequestBO requestBO) {
        startPage();
        Long userId = SecurityUtils.getLoginUser().getUserId();
        requestBO.setUserId(userId);
        List<MonthInOut> list = tradeingActivityService.getMonthInOutList(requestBO);
        return getDataTable(list);
    }

    @PostMapping("/invokeDify")
    @ResponseBody
    public AjaxResult invokeDify(String query) {
        String difyResult = null;
        try {
            difyResult = tradeingActivityService.invokeDify(query);
        } catch (IOException e) {
            log.error("调用dify出现异常,异常原因为{}",e.getMessage());
            return AjaxResult.error("调用dify出现异常");
        }
        return AjaxResult.success(difyResult);
    }
}
